package com.lqian.map;

import java.util.HashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class HashMapNotSafeDemo implements Runnable{
    

        private final static HashMap<String,String> map = new HashMap();

        private final static CountDownLatch latch = new CountDownLatch(1000);

        private String key;

        private String value;

        public HashMapNotSafeDemo(String key, String value){
            this.key = key;
            this.value = value;
        }

        @Override
        public void run() {
            map.put(key,value);
            latch.countDown();
        }


        public static void main(String[] args) {
            ExecutorService pool = Executors.newFixedThreadPool(8);
            try {
                for(int i = 1;i<=1000;i++){
                    HashMapNotSafeDemo demo = new HashMapNotSafeDemo("key"+i,"value"+i);
                    pool.execute(demo);
                }
                latch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                pool.shutdown();
            }
            System.out.println("map中的属性数量="+map.size());
        }
}
